package cn.com.chengmandian.bike.service.impl;

import cn.com.chengmandian.bike.model.EbMemberComboInfo;
import cn.com.chengmandian.bike.mapper.EbMemberComboInfoMapper;
import cn.com.chengmandian.bike.service.IEbMemberComboInfoService;
import cn.com.chengmandian.core.common.constants.CommonConstant;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 电单车运营-会员套餐 服务实现类
 * </p>
 *
 * @author AutoGenerator
 * @since 2023-08-28
 */
@Service
public class EbMemberComboInfoServiceImpl extends ServiceImpl<EbMemberComboInfoMapper, EbMemberComboInfo> implements IEbMemberComboInfoService {

    @Override
    public List<EbMemberComboInfo> getAvailableCombo(Integer areaId) {
        return this.list(new LambdaQueryWrapper<EbMemberComboInfo>()
                .eq(EbMemberComboInfo::getAreaId, areaId)
                .eq(EbMemberComboInfo::getIsDeleted, CommonConstant.ZERO)
                .eq(EbMemberComboInfo::getIsEnabled, CommonConstant.ONE)
                .orderByDesc(EbMemberComboInfo::getId));
    }

    @Override
    public EbMemberComboInfo getInfo(Integer comboId) {
        return this.getOne(new LambdaQueryWrapper<EbMemberComboInfo>()
                .eq(EbMemberComboInfo::getId, comboId)
                .eq(EbMemberComboInfo::getIsDeleted, CommonConstant.ZERO)
                .eq(EbMemberComboInfo::getIsEnabled, CommonConstant.ONE)
                .last("limit 0,1"));
    }
}
